package com.oreilly.justspring.core.ch1.ex15;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.oreilly.justspring.core.ch1.IReader;

/**
 * This is a client that reads the data using an implementation of IReader.
 * Notice the decoupling between the client and reader - client wouldn't know
 * who the reader is.
 * 
 * @author kondama
 * 
 */
public class DataReaderClient {
  private ApplicationContext ctx = null;
  private ReaderService service =  null;

  public DataReaderClient() {
    ctx = new ClassPathXmlApplicationContext("ex15-reader-beans.xml");
    service = (ReaderService) ctx.getBean("readerService");
  }

  private String fetchData() {
    return service.fetchData();
  }

  public static void main(String[] args) {

    DataReaderClient client = new DataReaderClient();
    System.out.println("Example 1.5: Got data: " + client.fetchData());
  }
}
